﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Roslyn.Compilers.Common;
using Roslyn.Services;

namespace Analysis.Rules
{
    class ConcreteClassFromSolutionVolatileChecker : IVolatileChecker
    {
        private IRoslynHelper helper;

        public ConcreteClassFromSolutionVolatileChecker(IRoslynHelper helper)
        {
            this.helper = helper;
        }

        public bool IsVolatile(CommonSyntaxNode node, IDocument doc)
        {
            var ts = helper.GetTypeAndSymbol(node, doc);

            var isTypeFromSolution = helper.GetAllProjectsInSolution(doc).Any(p => p.AssemblyName == ts.Item1.ContainingAssembly.Name);

            var isConcreteClass = true; // always true, since we're dealing with a new expression!

            return isTypeFromSolution && isConcreteClass;
        }
    }
}
